package com.neudeu.javaday01;

import java.util.*;

class 割圆术求Π {
    public static void main(String[] args) {
        int n;
        System.out.printf("输入切割次数：");
        Scanner input = new Scanner(System.in);
        n = input.nextInt();
        cyclotomic(n);
    }

    private static void cyclotomic(int n) {
        int i, s;
        double k, len;
        i = 0;
        k = 3.0;		//乘积值
        len = 1.0;		//半径
        s = 6;		//初始内接多边形边数
        while (i <= n) {
            System.out.printf("第%2d次切割，为正方形%5d边形，PI=%.24f\n", i, s,k * Math.sqrt(len));
            s *= 2;
            len = 2 - Math.sqrt(4 - len);
            i++;
            k *= 2.0;
        }
    }
}